"""
@Author  : 康帅
@Time    : 2021/8/2 17:35
@Function: 力扣：1.两数之和(容易)
"""


class Solution(object):

    def two_sum_method_one(self, nums, target):
        """
        一：暴利破解
        :type nums: List[int]
        :type target: int
        :rtype: List[int]
        :return: 两个组合成target值的下标
        """
        for i in range(len(nums)):
            for j in range(i + 1, len(nums)):
                if nums[i] == target - nums[j]:
                    return [i, j]
            return []

    def two_sum_method_two(self, nums, target):
        """
        二：哈希破解
        :type nums: List[int]
        :type target: int
        :rtype: List[int]
        :return:
        """
        hash_map = {}
        for _, value in enumerate(nums):
            another_value = target - value
            if another_value in hash_map:
                return [hash_map[another_value], _]
            hash_map[value] = _

        return None


if __name__ == '__main__':
    method = Solution()
    print(method.two_sum_method_one(nums=[2, 7, 11, 15], target=9))
    print(method.two_sum_method_two(nums=[11, 15, 2, 7], target=9))
